package com.finalx.TestPointerLocation;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;

public class TestPointerLocationActivity extends Activity {
	
	public final String TAG = "TestPointerLocationActivity";
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent mIntent = new Intent(getApplicationContext(), PointerLocationService.class);
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //startService(mIntent);
        setContentView(R.layout.main);
    }

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		Log.d(TAG, "@@@@ onKeyDown: keycode=" + keyCode + ", KeyEvent.getAction()=" + event.getAction());
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		Log.d(TAG, "@@@@ onKeyUp: keycode=" + keyCode + ", KeyEvent.getAction()=" + event.getAction());
		return super.onKeyUp(keyCode, event);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		printSamples(event);
		return super.onTouchEvent(event);
	}

	@Override
	public boolean onTrackballEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		return super.onTrackballEvent(event);
	}
    

	 void printSamples(MotionEvent ev) {
	     final int historySize = ev.getHistorySize();
	     final int pointerCount = ev.getPointerCount();
	     
	     //Log.d(TAG, "historysize=" + historySize + ", pointerCount=" + pointerCount);
	     
	     /*
	     for (int h = 0; h < historySize; h++) {
	         Log.d(TAG, "At historytime " + ev.getHistoricalEventTime(h));
	         for (int p = 0; p < pointerCount; p++) {
	             System.out.printf("  pointer %d: (%f,%f)",
	                 ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
	         }
	     }
	     */
	     
	     //Log.d(TAG, "At time:" + ev.getEventTime());
	     for (int p = 0; p < pointerCount; p++) {
	         Log.d(TAG, "  pointer " + ev.getPointerId(p) + " action" + ev.getAction() + ": (" + ev.getX(p) + ", " + ev.getY(p) + ")");
	     }
	 }

    
}